package com.ruoyi.project.zerocarbon.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ruoyi.common.constant.HttpStatus;
import com.ruoyi.common.exception.CustomException;
import com.ruoyi.common.utils.ServletUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.http.HttpUtils;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.security.LoginUser;
import com.ruoyi.framework.security.service.TokenService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.system.domain.SysUser;
import com.ruoyi.project.system.mapper.SysUserMapper;
import com.ruoyi.project.zerocarbon.auth.APIValidateUtil;
import com.ruoyi.project.zerocarbon.domain.DeclarationZhejiang;
import com.ruoyi.project.zerocarbon.domain.DeclareExpert;
import com.ruoyi.project.zerocarbon.domain.DeclareFunds;
import com.ruoyi.project.zerocarbon.domain.DeclareReporter;
import com.ruoyi.project.zerocarbon.domain.vo.DeclarationAuditVo;
import com.ruoyi.project.zerocarbon.domain.vo.DeclarationCenterAuditVo;
import com.ruoyi.project.zerocarbon.domain.vo.DeclareExpertGroupVo;
import com.ruoyi.project.zerocarbon.domain.vo.JudgeStatisticsVo;
import com.ruoyi.project.zerocarbon.mapper.*;
import com.ruoyi.project.zerocarbon.service.IDeclarationZhejiangService;
import com.ruoyi.project.zerocarbon.service.IDeclareExpertService;
import com.ruoyi.project.zerocarbon.service.IDeclareReporterService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.util.Assert;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.*;
import java.util.stream.Collectors;

import static com.ruoyi.common.utils.file.FileUtils.percentEncode;

/**
 * 【请填写功能名称】Controller
 * 
 * @author ruoyi
 * @date 2022-03-13
 */
@Slf4j
@Api("申报-浙江省")
@RestController
@RequestMapping("/declarationzj")
public class DeclarationZhejiangController extends BaseController
{
    @Autowired
    private IDeclarationZhejiangService declarationZhejiangService;
    @Autowired
    private IDeclareReporterService declareReporterService;
    @Autowired
    private IDeclareExpertService declareExpertService;
    @Autowired
    private DeclareExpertMapper declareExpertMapper;
    @Autowired
    private DeclarationZhejiangMapper declarationZhejiangMapper;
    @Autowired
    private DeclareExternalOrganizationMapper declareExternalOrganizationMapper;
    @Autowired
    private DeclareFundsMapper declareFundsMapper;
    @Autowired
    private DeclareMediaCoverageMapper declareMediaCoverageMapper;
    @Autowired
    private DeclareImplementationPlanMapper declareImplementationPlanMapper;
    @Autowired
    private TokenService tokenService;
    @Autowired
    private SysUserMapper userMapper;

    @Value("${declaration.auth.accessKeyId}")
    private String accessKeyId;
    @Value("${declaration.auth.accessKeySecret}")
    private String accessKeySecret;

    /**
     * 新增【请填写功能名称】
     */
    @ApiOperation("保存或编辑或提交申报，免拦截")
    @PostMapping("/addOrUpdate")
    public AjaxResult addOrUpdate(@Validated @RequestBody DeclarationZhejiang declarationZhejiang)
    {
        Assert.notNull(declarationZhejiang.getUserName(),"userName cannot be null");
        return toAjax(declarationZhejiangService.insertDeclarationZhejiang(declarationZhejiang));
    }

    @ApiOperation("推荐号，根据id")
    @PostMapping("/setRecommendNum")
    public AjaxResult setRecommendNum(@RequestBody DeclarationZhejiang declarationZhejiang)
    {
        Assert.notNull(declarationZhejiang.getId(),"id cannot be null");
        return toAjax(declarationZhejiangService.updateDeclarationZhejiang(declarationZhejiang));
    }

    /**
     * 新增【请填写功能名称】
     */
    @ApiOperation("查看申报，前台使用，根据account，免拦截")
    @GetMapping("/detailByUserName")
    public AjaxResult detailByAccount(String userName)
    {
        Assert.notNull(userName,"userName cannot be null");
        return AjaxResult.success(declarationZhejiangService.selectDeclarationZhejiangByUserName(userName));
    }

    @ApiOperation("查看申报，根据id")
    @GetMapping("/detailById")
    public AjaxResult detail(Long id)
    {
        Assert.notNull(id,"id cannot be null");
        DeclarationZhejiang declarationZhejiang = declarationZhejiangMapper.selectDeclarationDetailZhejiangById(id);
        if (declarationZhejiang != null){
            declarationZhejiang.setExternalOrganizations(declareExternalOrganizationMapper.selectDeclareExternalOrganizationByDeclarationId(declarationZhejiang.getId()));
            declarationZhejiang.setFunds(declareFundsMapper.selectDeclareFundsByDeclarationId(declarationZhejiang.getId()));
            declarationZhejiang.setImplementationPlans(declareImplementationPlanMapper.selectDeclareImplementationPlanByDeclarationId(declarationZhejiang.getId()));
            declarationZhejiang.setMediaCoverages(declareMediaCoverageMapper.selectDeclareMediaCoverageByDeclarationId(declarationZhejiang.getId()));
        }
        return AjaxResult.success(declarationZhejiang);
    }

    @ApiOperation("项目报名列表,待审核11、淘汰12、通过13;auditStatus>=13都是通过")
    @PostMapping("/signUp/list")
    public TableDataInfo signUpList(@Validated @RequestBody DeclarationZhejiang declarationZhejiang) {
        startPage();
        declarationZhejiang.setSaveType(1);
        if (declarationZhejiang.getAuditStatus() == null) {

        } else if (declarationZhejiang.getAuditStatus() == 13) {
            declarationZhejiang.setAuditStatusList(Arrays.asList(13, 21, 22, 23, 24, 25));
        }
        List<DeclarationZhejiang> list = declarationZhejiangService.selectDeclarationZhejiangList(declarationZhejiang);
        //0：待提交（草稿）；1：已提交; 2:已报名（APP预约）
        return getDataTable(list);
    }


    @ApiOperation("更新(根据id)")
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody DeclarationZhejiang declarationZhejiang) {
        Assert.notNull(declarationZhejiang.getId());
//        if (!StringUtils.isEmpty(declarationZhejiang.getRecommendNum())){
//            DeclarationZhejiang history = declarationZhejiangMapper.selectDeclarationDetailZhejiangById(declarationZhejiang.getId());
//            List<Declaration> declarations = declarationMapper.selectDeclarationList(declarationVo);
//            if (StringUtils.isNotEmpty(declarations)){
//                //                throw new CustomException("同一省份推荐号不可重复！");
//                return AjaxResult.error("同一省份推荐号不可重复！");
//            }
//        }
        declarationZhejiang.setUpdateTime(new Date());
        return toAjax(declarationZhejiangService.updateDeclarationZhejiang(declarationZhejiang));
    }

    /**
     * 上报列表
     *
     * @param declarationZhejiang
     * @return
     */
    @ApiOperation("上报列表")
    @PostMapping("/report/list")
    public TableDataInfo reportList(@Validated @RequestBody DeclarationZhejiang declarationZhejiang) {
        startPage();
        if (declarationZhejiang.getAuditStatus() == null || declarationZhejiang.getAuditStatus() < 13) {
            declarationZhejiang.setAuditStatusList(Arrays.asList(13,21,22,24,25));
        }
        List<DeclarationZhejiang> list = declarationZhejiangService.selectDeclarationZhejiangList(declarationZhejiang);
        //0：待提交（草稿）；1：已提交; 2:已报名（APP预约）
        return getDataTable(list);
    }

    /**
     * 新增【请填写功能名称】
     */
    @ApiOperation("上报人提交")
    @PostMapping("/report/add")
    public AjaxResult addReporter(@RequestBody DeclareReporter declareReporter) {
        //todo 检查原状态是否为待提交
        if (declareReporter.getDeclarationId() != null) {
            Long declarationId = declareReporter.getDeclarationId();
            DeclarationZhejiang declarationZJ = new DeclarationZhejiang();
            declarationZJ.setId(declarationId);
            declarationZJ.setAuditStatus(21);
            declarationZJ.setReporter(declareReporter.getReporter());
            declarationZhejiangService.updateDeclarationZhejiang(declarationZJ);
            DeclareReporter reporter = declareReporterService.selectDeclareReporterByDeclarationId(declarationId);
            if (reporter != null) {
                reporter.setPicture(declareReporter.getPicture());
                reporter.setContactNumber(declareReporter.getContactNumber());
                reporter.setReporter(declareReporter.getReporter());
                declareReporterService.updateDeclareReporter(reporter);
            } else {
                declareReporterService.insertDeclareReporter(declareReporter);
            }
            return AjaxResult.success();
        }
        if (CollectionUtils.isNotEmpty(declareReporter.getDeclarationIdList())) {
            for (int i = 0; i < declareReporter.getDeclarationIdList().size(); i++) {
                Long declarationId = declareReporter.getDeclarationIdList().get(i);
                DeclareReporter reporter = declareReporterService.selectDeclareReporterByDeclarationId(declarationId);
                if (reporter != null) {
                    reporter.setPicture(declareReporter.getPicture());
                    reporter.setContactNumber(declareReporter.getContactNumber());
                    reporter.setReporter(declareReporter.getReporter());
                    declareReporterService.updateDeclareReporter(reporter);
                } else {
                    declareReporterService.insertDeclareReporter(declareReporter);
                }
                DeclarationZhejiang declarationZJ = new DeclarationZhejiang();
                declarationZJ.setId(declarationId);
                declarationZJ.setAuditStatus(21);
                declarationZJ.setReporter(declareReporter.getReporter());
                declarationZhejiangService.updateDeclarationZhejiang(declarationZJ);
            }
        }
        return AjaxResult.success();
    }

    /**
     * decoration
     *
     * @param declarationZhejiang
     * @return
     */
    @ApiOperation("团省委审核项目列表，需按上报人倒序")
    @PostMapping("/check/list")
    public TableDataInfo checkList(@Validated @RequestBody DeclarationZhejiang declarationZhejiang) {
        startPage();
        if (declarationZhejiang.getAuditStatus() == null || declarationZhejiang.getAuditStatus() < 21) {
            declarationZhejiang.setAuditStatusList(Arrays.asList(21, 24));
        }
        List<DeclarationZhejiang> list = declarationZhejiangService.selectDeclarationZhejiangList(declarationZhejiang);
        if (CollectionUtils.isNotEmpty(list)) {
            for (DeclarationZhejiang declaration : list) {
                DeclareReporter reporter = declareReporterService.selectDeclareReporterByDeclarationId(declaration.getId());
                if (reporter != null) {
                    declaration.setReporter(reporter.getReporter());
                    declaration.setReporterContactNumber(reporter.getContactNumber());
                }
            }
        }
        return getDataTable(list);
    }

    @ApiOperation("团省委审核,通过或驳回（批量）")
    @PostMapping("/check/edit")
    public AjaxResult editBatch(@Validated @RequestBody DeclarationAuditVo declarationAuditVo) {
        for (Long id : declarationAuditVo.getDeclarationIdList()) {
            DeclarationZhejiang declaration = new DeclarationZhejiang();
            declaration.setId(id);
            declaration.setAuditStatus(declarationAuditVo.getAuditStatus());
            if (StringUtils.isNotEmpty(declarationAuditVo.getAuditComment())){

            }
            declaration.setAuditComment(declarationAuditVo.getAuditComment());
            declaration.setCenterComment(declarationAuditVo.getCenterComment());
            declarationZhejiangService.updateDeclarationZhejiang(declaration);
        }
        return AjaxResult.success();
    }

    /**
     * 审核接口
     */
    @ApiOperation("团省委审核列表下载图片接口,根据上报人手机号")
    @GetMapping("/city/picList")
    public AjaxResult auditDecoration(String contactNumber) {
        Assert.notNull(contactNumber);
        DeclareReporter declareReporter = new DeclareReporter();
        declareReporter.setContactNumber(contactNumber);
        List<DeclareReporter> declareReporters = declareReporterService.selectDeclareReporterList(declareReporter);
        List<String> picUrls = new ArrayList<>();
        if (CollectionUtils.isNotEmpty(declareReporters)){
            declareReporters = declareReporters.stream().sorted(Comparator.comparing(DeclareReporter::getId).reversed()).collect(Collectors.toList());
            String picture = declareReporters.get(declareReporters.size() - 1).getPicture();
            if (!StringUtils.isEmpty(picture)){
                picUrls.add(picture);
            }
        }
        return AjaxResult.success(picUrls);
    }

    @ApiOperation("团省委审核提交人centerComment审核状态")
    @PostMapping("/decoration/centerCheck/edit")
    public AjaxResult centerCheck(@Validated @RequestBody DeclarationCenterAuditVo declarationAuditVo) {
        Assert.notNull(declarationAuditVo.getAuditStatus());
        if (CollectionUtils.isNotEmpty(declarationAuditVo.getIdList())){
            for (Long id:declarationAuditVo.getIdList()){
                DeclarationZhejiang model = declarationZhejiangService.selectDeclarationZhejiangById(id);
                model.setAuditStatus(declarationAuditVo.getAuditStatus());
                model.setCenterComment(declarationAuditVo.getCenterComment());
                declarationZhejiangService.updateDeclarationZhejiang(model);
                DeclareReporter declareReporter = new DeclareReporter();
                declareReporter.setReporter(declarationAuditVo.getReporter());
                DeclareReporter reporter = declareReporterService.selectDeclareReporterByDeclarationId(id);
                if (declarationAuditVo.getAuditStatus() == 25){
                    sendMessage(reporter.getContactNumber(),"您好，您所提交的青年志愿服务项目大赛，序号："+model.getRegionSerial()+"评审资料已被系统驳回，请登录评审系统查看修改。");
                }else if (declarationAuditVo.getAuditStatus() == 24){
                    sendMessage(reporter.getContactNumber(),"您好，您所提交的青年志愿服务项目大赛，序号："+model.getRegionSerial()+"评审资料已通过。");
                }
            }
        }else {
            Assert.notNull(declarationAuditVo.getReporter());
            DeclarationZhejiang declaration = new DeclarationZhejiang();
            declaration.setReporter(declarationAuditVo.getReporter());
            List<DeclarationZhejiang> declarations = declarationZhejiangService.selectDeclarationZhejiangList(declaration);
            for (DeclarationZhejiang model:declarations){
                model.setAuditStatus(declarationAuditVo.getAuditStatus());
                model.setCenterComment(declarationAuditVo.getCenterComment());
                declarationZhejiangService.updateDeclarationZhejiang(model);
            }
            DeclareReporter declareReporter = new DeclareReporter();
            declareReporter.setReporter(declarationAuditVo.getReporter());
            List<DeclareReporter> declareReporters = declareReporterService.selectDeclareReporterList(declareReporter);
            if (declarationAuditVo.getAuditStatus() == 25){
                sendMessage(declareReporters.get(declareReporters.size()-1).getContactNumber(),"您好，您所提交的青年志愿服务项目大赛评审资料已被系统驳回，请登录评审系统查看修改。");
            }else {
                sendMessage(declareReporters.get(declareReporters.size()-1).getContactNumber(),"您好，您所提交的青年志愿服务项目大赛评审资料已通过。");
            }
        }
        return AjaxResult.success();
    }

    private String mailUrl = "https://third.api.zyh365.com/api/comm/sendMessage.do";
    private void sendMessage(String phone,String message){
        Map<String,String> mapv=new HashMap<String, String>();
        mapv.put("AccessKeyId", accessKeyId);
        mapv.put("tel", phone);
        mapv.put("message", message);
        String response = null;
        try {
            String key = new APIValidateUtil().computeSignature(mapv, accessKeySecret);
            String rspStr = "tel="+phone+"&message="+message+"&AccessKeyId="+mapv.get("AccessKeyId")+"&Signature="+percentEncode(key);
            response = HttpUtils.sendPost(mailUrl, rspStr);
            log.info("发送团省委审核短信 phone：{}，response: {}",phone,response);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 评审委员会分配列表
     *
     * @param declarationZhejiang
     * @return
     */
    @ApiOperation("评审委员会分配列表")
    @PostMapping("/distribution/list")
    public TableDataInfo distributionList(@Validated @RequestBody DeclarationZhejiang declarationZhejiang) {
        startPage();
        if (declarationZhejiang.getAuditStatus() == null || declarationZhejiang.getAuditStatus() < 21) {
            declarationZhejiang.setAuditStatus(24);
        }
        List<DeclarationZhejiang> list = declarationZhejiangService.selectDeclarationZhejiangList(declarationZhejiang);
        for(DeclarationZhejiang declaration:list){
            DeclareExpert declareExpert = declareExpertMapper.selectDeclareExpertByDeclarationId(declaration.getId());
            if (declareExpert != null){
                declaration.setGroupName(declareExpert.getGroupName());
            }
        }
        return getDataTable(list);
    }

    @ApiOperation("评审委员会小组选择列表")
    @GetMapping("/group/selectList")
    public AjaxResult selectList()
    {
        List<DeclareExpertGroupVo> list = new ArrayList<>();
        String[] group1Names = {
                "第1组",
                "第2组",
                "第3组",
                "第4组"
        };
        for (int i = 0; i < group1Names.length; i++) {
            int count = declareExpertMapper.countExpertByGroupName(group1Names[i]);
            DeclareExpertGroupVo vo = new DeclareExpertGroupVo();
            vo.setGroupName(group1Names[i]);
            vo.setNum(count);
            list.add(vo);
        }
        return AjaxResult.success(list);
    }

    @ApiOperation("评审委员会小组项目列表，每页5条")
    @PostMapping("/group/list")
    public TableDataInfo groupList(@RequestBody DeclarationZhejiang declarationZhejiang) {
        startPage();
        String groupName = declarationZhejiang.getGroupName();
        Assert.notNull(groupName,"groupName cannot be null");
        List<DeclarationZhejiang> list = declarationZhejiangMapper.getGroupDecorationList(declarationZhejiang);
        //0：待提交（草稿）；1：已提交; 2:已报名（APP预约）
        return getDataTable(list);
    }

    @ApiOperation("评审委员会专家列表")
    @GetMapping("/group/viewByGroupName")
    public AjaxResult groupView(String groupName)
    {
        Assert.notNull(groupName);
        List<SysUser> sysUsers = userMapper.selectUserByRemark(groupName);
        return AjaxResult.success(sysUsers);
    }

    /**
     * 新增【请填写功能名称】
     */
    @ApiOperation("评审委员会选择专家，declarationIdList和groupName")
    @PostMapping("/expert/add")
    public AjaxResult selectExpert(@RequestBody DeclareExpert declareExpert)
    {
        Assert.notNull(declareExpert.getGroupName());
        if (CollectionUtils.isNotEmpty(declareExpert.getDeclarationIdList())){
            for (int i = 0; i < declareExpert.getDeclarationIdList().size(); i++) {
                DeclareExpert modelE = declareExpertMapper.selectDeclareExpertByDeclarationId(declareExpert.getDeclarationIdList().get(i));
                if (modelE != null){
                    throw new CustomException("不能重复分配");
                }
                modelE = new DeclareExpert();
                BeanUtils.copyProperties(declareExpert,modelE);
                modelE.setDeclarationId(declareExpert.getDeclarationIdList().get(i));
                int i1 = declareExpertService.insertDeclareExpert(modelE);
                DeclarationZhejiang declaration = new DeclarationZhejiang();
                declaration.setId(declareExpert.getDeclarationIdList().get(i));
                declaration.setDistributionStatus(1);
                declarationZhejiangService.updateDeclarationZhejiang(declaration);
            }
        }
        return AjaxResult.success();
    }

    /**
     * 评分列表
     *
     * @param declarationZhejiang
     * @return
     */
    @ApiOperation("评分列表")
    @PostMapping("/judge/list")
    public TableDataInfo judgeList(@Validated @RequestBody DeclarationZhejiang declarationZhejiang) {
        List<DeclarationZhejiang> list = new ArrayList<>();
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        String groupName = loginUser.getUser().getRemark();
        declarationZhejiang.setGroupName(groupName);
        if (StringUtils.isEmpty(groupName)){
            return getDataTable(list);
        }

        declarationZhejiang.setDistributionStatus(1);
        if (declarationZhejiang.getAuditStatus() == null || declarationZhejiang.getAuditStatus() < 23) {
            declarationZhejiang.setAuditStatus(24);
        }
        Integer pageNum = declarationZhejiang.getPageNum() != null ? declarationZhejiang.getPageNum() : 1;
        Integer pageSize = declarationZhejiang.getPageSize() != null ? declarationZhejiang.getPageSize() : 500;
        String orderBy = "id desc";
        if (StringUtils.isNotNull(pageNum) && StringUtils.isNotNull(pageSize)) {
            PageHelper.startPage(pageNum, pageSize);
        }
        List<DeclarationZhejiang> groupDecorationList;
        if (declarationZhejiang.getJudgeStatus() != null && declarationZhejiang.getJudgeStatus() ==0){
            declarationZhejiang.setUserName(loginUser.getUser().getUserName());
            groupDecorationList = declarationZhejiangMapper.getGroupDecorationListAndNoJudgeStatus(declarationZhejiang);
        }else if (declarationZhejiang.getJudgeStatus() != null && declarationZhejiang.getJudgeStatus() > 0){
            declarationZhejiang.setUserName(loginUser.getUser().getUserName());
            groupDecorationList = declarationZhejiangMapper.getGroupDecorationListAndJudgeStatus(declarationZhejiang);
        }else {
            groupDecorationList = declarationZhejiangMapper.getGroupDecorationList(declarationZhejiang);
        }
        list = declarationZhejiangService.getJudgeDecorationListByVoList(groupDecorationList,declarationZhejiang.getJudgeStatus(),loginUser.getUser().getUserName());

        TableDataInfo rspData = new TableDataInfo();
        rspData.setCode(HttpStatus.SUCCESS);
        rspData.setMsg("查询成功");
        rspData.setRows(list);
        rspData.setTotal(new PageInfo(groupDecorationList).getTotal());
        return rspData;
    }

    @ApiOperation("评分列表统计")
    @GetMapping("/judge/statistics")
    public AjaxResult judgeStatistics() {
//        1.项目总数
//        2.待评分
//        3.已评分
//        4.已提交
        JudgeStatisticsVo judgeStatisticsVo = new JudgeStatisticsVo();
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        String groupName = loginUser.getUser().getRemark();
        DeclarationZhejiang declarationZhejiang = new DeclarationZhejiang();
        declarationZhejiang.setGroupName(groupName);
        if (StringUtils.isEmpty(groupName)){
            return AjaxResult.success(judgeStatisticsVo);
        }
//        private int total;
//        private int preJudge;
//        private int judged;
//        private int submitted;
        int total = declarationZhejiangMapper.countGroupDecorationList(declarationZhejiang);
        declarationZhejiang.setUserName(loginUser.getUser().getUserName());
        int preJudge = declarationZhejiangMapper.countGroupDecorationListAndNoJudgeStatus(declarationZhejiang);
        declarationZhejiang.setJudgeStatus(1);
        int judged = declarationZhejiangMapper.countGroupDecorationListAndJudgeStatus(declarationZhejiang);
        declarationZhejiang.setJudgeStatus(2);
        int submitted = declarationZhejiangMapper.countGroupDecorationListAndJudgeStatus(declarationZhejiang);
        judgeStatisticsVo.setTotal(total);
        judgeStatisticsVo.setPreJudge(preJudge);
        judgeStatisticsVo.setJudged(judged);
        judgeStatisticsVo.setSubmitted(submitted);
        return AjaxResult.success(judgeStatisticsVo);
    }

    /**
     * 评审委员会,项目排名列表
     *
     * @param declarationZhejiang
     * @return
     */
    @ApiOperation("评审委员会,项目排名列表")
    @PostMapping("/ranking/list")
    public TableDataInfo rankingList(@Validated @RequestBody DeclarationZhejiang declarationZhejiang) {
        Integer pageNum = declarationZhejiang.getPageNum() != null ? declarationZhejiang.getPageNum() : 1;
        Integer pageSize = declarationZhejiang.getPageSize() != null ? declarationZhejiang.getPageSize() : 20;
        String orderBy = "dr.score desc";
        if (StringUtils.isNotNull(pageNum) && StringUtils.isNotNull(pageSize)) {
            PageHelper.startPage(pageNum, pageSize, orderBy);
        }

        if (declarationZhejiang.getAuditStatus() == null || declarationZhejiang.getAuditStatus() < 23) {
            declarationZhejiang.setAuditStatus(24);
        }
        declarationZhejiang.setDistributionStatus(1);
        List<DeclarationZhejiang> list = declarationZhejiangService.getRankingDecorationList(declarationZhejiang);
        //0：待提交（草稿）；1：已提交; 2:已报名（APP预约）
        return getDataTable(list);
    }

    /**
     * 删除【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('zerocarbon:zhejiang:remove')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(declarationZhejiangService.deleteDeclarationZhejiangByIds(ids));
    }

    public static void main(String[] args) {
        DeclareFunds funds1 = new DeclareFunds();
        DeclareFunds funds2 = new DeclareFunds();
        DeclareFunds funds3 = new DeclareFunds();
        funds1.setProjectExpenditure("");
        funds2.setProjectExpenditure("");
        funds3.setProjectExpenditure("");
        List<DeclareFunds> list = new ArrayList<>();
        list.add(funds1);
        list.add(funds2);
        list.add(funds3);
        String collect = list.stream().map(DeclareFunds::getProjectExpenditure).collect(Collectors.joining("\n"));
        System.out.println(collect);
    }
}
